package com.payment.ktb.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.payment.ktb.R;
import com.payment.ktb.application.MyApplication;
import com.payment.ktb.model.SettleBankCard;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by syd on 2016/8/1.
 */
public class SettleBankCardRecordAdapter extends BaseAdapter {

    Context mContext;
    List<SettleBankCard> listData = new ArrayList<SettleBankCard>();


    public SettleBankCardRecordAdapter(List<SettleBankCard> listData, Context mContext) {
        this.listData = listData;
        this.mContext = mContext;
    }


    @Override
    public int getCount() {
        return listData.size();
    }

    @Override
    public Object getItem(int position) {
        return listData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.adapter_settlebankcardmanagehascard_item,null);
            viewHolder.tv_settlebankcardmanagehascard_adapter_time = (TextView) convertView.findViewById(R.id.tv_settlebankcardmanagehascard_adapter_time);
            viewHolder.tv_settlebankcardmanagehascard_adapter_bankNick = (TextView) convertView.findViewById(R.id.tv_settlebankcardmanagehascard_adapter_bankNice);
            viewHolder.tv_settlebankcardmanagehascard_adapter_bankNum = (TextView) convertView.findViewById(R.id.tv_settlebankcardmanagehascard_adapter_bankNum);
            viewHolder.tv_settlebankcardmanagehascard_adapter_bankStatus = (TextView) convertView.findViewById(R.id.tv_settlebankcardmanagehascard_adapter_bankStatus);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv_settlebankcardmanagehascard_adapter_time.setText(listData.get(position).getCreateTime());
        viewHolder.tv_settlebankcardmanagehascard_adapter_bankNick.setText(listData.get(position).getBankNick());
        viewHolder.tv_settlebankcardmanagehascard_adapter_bankNum.setText(listData.get(position).getBankNo());

        /**
         * INIT(0,"初始化").
         WAIT(1,"等待处理");
         SUCC(2,"处理成功");
         FAIL(3,"处理失败");
         HOLD(9,"保留");
         */
        if ("0".equals(listData.get(position).getTaskStatus())) {
            viewHolder.tv_settlebankcardmanagehascard_adapter_bankStatus.setText("初始化");
            viewHolder.tv_settlebankcardmanagehascard_adapter_bankStatus.setTextColor(MyApplication.getContext().getResources().getColor(R.color.text464646));
        } else if ("1".equals(listData.get(position).getTaskStatus())) {
            viewHolder.tv_settlebankcardmanagehascard_adapter_bankStatus.setText("等待处理");
            viewHolder.tv_settlebankcardmanagehascard_adapter_bankStatus.setTextColor(MyApplication.getContext().getResources().getColor(R.color.text464646));
        } else if ("2".equals(listData.get(position).getTaskStatus())) {
            viewHolder.tv_settlebankcardmanagehascard_adapter_bankStatus.setText("处理成功");
            viewHolder.tv_settlebankcardmanagehascard_adapter_bankStatus.setTextColor(MyApplication.getContext().getResources().getColor(R.color.green));
        } else if ("3".equals(listData.get(position).getTaskStatus())) {
            viewHolder.tv_settlebankcardmanagehascard_adapter_bankStatus.setText("处理失败");
            viewHolder.tv_settlebankcardmanagehascard_adapter_bankStatus.setTextColor(MyApplication.getContext().getResources().getColor(R.color.red));
        } else if ("9".equals(listData.get(position).getTaskStatus())) {
            viewHolder.tv_settlebankcardmanagehascard_adapter_bankStatus.setText("保留");
            viewHolder.tv_settlebankcardmanagehascard_adapter_bankStatus.setTextColor(MyApplication.getContext().getResources().getColor(R.color.text464646));
        } else {
            viewHolder.tv_settlebankcardmanagehascard_adapter_bankStatus.setText("其它");
            viewHolder.tv_settlebankcardmanagehascard_adapter_bankStatus.setTextColor(MyApplication.getContext().getResources().getColor(R.color.text464646));
        }


        return convertView;
    }


    private class ViewHolder {
        TextView tv_settlebankcardmanagehascard_adapter_time;
        TextView tv_settlebankcardmanagehascard_adapter_bankNick;
        TextView tv_settlebankcardmanagehascard_adapter_bankNum;
        TextView tv_settlebankcardmanagehascard_adapter_bankStatus;
    }



}
